package org.example.server.app.goods.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.frw.api.base.response.PageResponse;
import org.example.server.app.goods.mapstruct.GoodsAppConverter;
import org.example.server.app.goods.request.GoodsSearchAppRequest;
import org.example.server.app.goods.response.PageAppResponse;
import org.example.server.app.goods.response.goods.Goods;
import org.example.server.app.goods.service.GoodsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsAppController {
  @Resource
  private GoodsService goodsService;
  @Resource
  private GoodsAppConverter goodsAppConverter;

  @PostMapping("/search")
  public PageAppResponse<Goods> searchGoods(@RequestBody GoodsSearchAppRequest searchRequest){
    log.info("received request: GoodsAppController.searchGoods. pageQueryRequest = {} ,searchRequest={}",searchRequest.getPage(),searchRequest);
    PageResponse<Goods> goodsPageResponse = goodsService.searchGoods(searchRequest);
    return goodsAppConverter.toPageAppResponse(goodsPageResponse);
  }
}
